<?php

use App\Http\Controllers\Admin\AuthController;
use App\Http\Controllers\Admin\DashboardController;
use App\Http\Controllers\Admin\Setting\Permission\AccountController;
use App\Http\Controllers\Admin\Setting\Permission\MenuController;
use App\Http\Controllers\Admin\Setting\Permission\RoleController;
use App\Http\Controllers\Admin\Setting\WebSiteController;
use App\Http\Controllers\Admin\Setting\Wechat\WeChatConfigController;
use App\Http\Controllers\Admin\Setting\Wechat\WeChatDraftController;
use App\Http\Controllers\Admin\Setting\Wechat\WeChatMaterialController;
use App\Http\Controllers\Admin\Setting\Wechat\WeChatMenuController;
use App\Http\Controllers\Admin\Setting\Wechat\WeChatMessageController;
use App\Http\Controllers\Admin\UploadController;
use Illuminate\Support\Facades\Route;

// 游客
Route::middleware('guest')->group(function () {
    Route::get('auth/login', [AuthController::class, 'login'])->name('login');
    Route::post('auth/authenticate', [AuthController::class, 'authenticate'])->name('authenticate');
});

// 管理员
Route::get('/', function () {
    return redirect()->route('admin.login'); // 使用命名路由
})->name('welcome');

Route::middleware(['auth_admin'])->group(function () {
    Route::get('logout', [AuthController::class, 'logout'])->name('logout');
    // 仪表盘路由（统一前缀）
    Route::prefix('dashboard')->name('dashboard.')->group(function () {
        Route::get('workplace', [DashboardController::class, 'workplace'])->name('workplace');
        Route::get('analysis', [DashboardController::class, 'analysis'])->name('analysis');
    });


    //设置
    Route::prefix('setting')->name('setting.')->group(function () {
        Route::get('website', [WebSiteController::class, 'index'])->name('website.index');
        Route::post('website', [WebSiteController::class, 'update'])->name('website.update');
        // 权限
        Route::prefix('permissions')->name('permissions.')->group(function () {
            Route::apiResource('accounts', AccountController::class)->names('accounts');
            Route::apiResource('roles', RoleController::class)->names('roles');
            Route::apiResource('menus', MenuController::class)->names('menus');
        });

        // 微信公众号模块
        Route::prefix('wechat')->name('wechat.')->group(function () {
            Route::get('configs', [WeChatConfigController::class, 'index'])->name('configs.index');
            Route::post('configs', [WeChatConfigController::class, 'update'])->name('configs.update');
            Route::get('menus', [WeChatMenuController::class, 'index'])->name('menus.index');
            Route::post('menus', [WeChatMenuController::class, 'update'])->name('menus.update');
            Route::apiResource('messages', WeChatMessageController::class)->names('messages');
            Route::apiResource('drafts', WeChatDraftController::class)->names('drafts');
//            Route::apiResource('releases', WeChatReleaseController::class)->names('releases');
            Route::apiResource('materials', WeChatMaterialController::class)->names('materials');
        });
    });

    // 文件上传
    Route::prefix('upload')->name('upload.')->group(function () {
        Route::post('image', [UploadController::class, 'image'])->name('image');
        Route::post('avatar', [UploadController::class, 'avatar'])->name('avatar');
    });
});
